import csv

class Log:
    def __init__(self, filename):
        self.log = {}
        self.file = open(filename, "a", newline='')
        self.write = csv.writer(self.file , dialect='excel')
        self.write.writerow(['日期', '持仓总市值', '收益率', "持有股票{代码:手数}"])

    def record_log(self, date, total_value, rate, hold_stock):
        self.log[date] = {
            'total_value': total_value,
            'rate': rate,
        }
        self.write.writerow([date,total_value, rate, hold_stock])
